package com.edu.service.impl;

import com.edu.beans.Home;
import com.edu.dao.BookDao;
import com.edu.dao.HomeDao;
import com.edu.dao.impl.BookDaoImpl;
import com.edu.dao.impl.HomeDaoImpl;
import com.edu.exception.UsedException;
import com.edu.service.HomeService;

import java.util.Collections;
import java.util.List;

public class HomeServiceImpl implements HomeService {

    HomeDao homeDao = new HomeDaoImpl();

    @Override
    public int addHome(Home home) {
        return homeDao.addHome(home);
    }

    @Override
    public int deleteHomeById(int id) throws UsedException {
        Home home = homeDao.getHomeById(id);
        if ("已入住".equals(home.getState())) {
            // 如果房间已入住，不能删除
            throw new UsedException("该房间已被入住，不能删除！");
        } else {
            return homeDao.deleteHomeById(id);
        }
    }

    @Override
    public int updateHome(Home home) {
        return homeDao.updateHome(home);
    }

    @Override
    public Home getHomeById(int id) {
        return homeDao.getHomeById(id);
    }

    @Override
    public List<Home> getAllHomeByNum(String num) {
        return homeDao.getAllHomeByNum(num);
    }

    @Override
    public List<Home> getHomeByState(String state) {
        return homeDao.getHomeByState(state);
    }
}
